<?php

class Bootstrap extends \Yaf\Bootstrap_Abstract
{
    /**
     * 注册composer
     */
    public function _initAutoload(\Yaf\Dispatcher $dispatcher) {
        // Autoload 自动载入
        require "D:/phpstudy_pro/WWW/ctrl/vendor/autoload.php";
    }

    public function _initDb(\Yaf\Dispatcher $dispatcher){
        $DbConfig = \Yaf\Application::app()->getConfig()->toArray()['db'];
        $DbConfig['class']  = \TC\Db\Mysql::class;

        \Yaf\Registry::set('db_config',$DbConfig);
        \TC\Di\Container::set('Yaf_Com_Dispatcher',$dispatcher);
    }

    public function _initRpc(\Yaf\Dispatcher $dispatcher)
    {
        $handler = ltrim($_SERVER['REQUEST_URI'],'/');
        $class = 'service\\'.ucfirst($handler);
        if(!class_exists($class)) {
           \TC\IO\Output::rpcFail('500','9001','rpc错误');
        }
        $server = new \Yar_Server(new $class([
            'dispatcher' => $dispatcher
        ]));
        $server->handle();
    }

}